package com.twu.biblioteca.operation;

import com.twu.biblioteca.service.UserService;

import static com.twu.biblioteca.util.Messages.*;

public class LoginSystemOperation extends Operation {
    UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @Override
    public String operate(String[] args) throws Exception {
        String accountId = args[0];
        String password = args[1];
        boolean flag = userService.checkLogin(accountId);
        if (!flag) {
            boolean result = userService.userLogin(accountId, password);
            if (result) {
                return LOGIN_SUCCESS;
            } else {
                return ACCOUN_ID_OR_PASSWORD_WRONG_PLEASE_TRY_AGAIN;
            }
        } else {
            return YOU_HAVE_LOGIN;
        }
    }
}
